package com.ytxg.util.jdk8.lambda;

import java.util.function.Function;
import java.util.function.Predicate;

public class Main {
    public static void main(String[] args) {

        Function<String, String> replaceABC = str -> str.replace("abc", "dbc");
        Function<String, String> removeSpaces = str -> str.replaceAll("\\s+", "");
        Function<String, String> getLastSegment = str -> {
            String[] parts = str.split(",");
            return parts[parts.length - 1];
        };

        String result1 = replaceABC.apply("abcabcabc");
        String result2 = removeSpaces.apply("abc abc");
        String result3 = getLastSegment.apply("110,010,000,111");
        System.out.println("逻辑1结果: " + result1);
        System.out.println("逻辑2结果: " + result2);
        System.out.println("逻辑3结果: " + result3);


        Predicate<String> containsABC = str -> str.contains("abcabcabc") || str.contains("abc");
        Predicate<String> endsWithC = str -> str.endsWith("abc") && str.charAt(str.length() - 1) == 'c';
        boolean result4 = containsABC.test("abcabcabc");
        boolean result5 = endsWithC.test("xyzabc");
        System.out.println("逻辑4结果: " + result4);
        System.out.println("逻辑5结果: " + result5);
    }
}
